﻿using Dapper;
using DirectSell.IBLL;
using DirectSell.Model.Money;
using DirectSell.Model.User;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Direct.IDAL
{
    /// <summary>
    /// 用户数据访问基类
    /// </summary>
    public interface IAbsRepository
    {
        #region 查询--郭文昊--2018年8月9日23:28:38
        /// <summary>
        /// 查询
        /// </summary>
        /// <typeparam name="R"></typeparam>
        /// <param name="sql"></param>
        /// <returns></returns>
        IEnumerable<R> Query<R>(string sql);
        /// <summary>
        /// 查询 异步
        /// </summary>
        /// <param name="sql">查询语句</param>
        /// <returns></returns>
        Task<IEnumerable<R>> QueryAsync<R>(string sql);
        #endregion

        #region 修改--郭文昊--2018年8月9日23:29:25
        /// <summary>
        /// 修改方法
        /// </summary>
        /// <param name="setValue"></param>
        /// <param name="strWhere"></param>
        /// <param name="hsTable"></param>
        void Update(string setValue, string strWhere, ref Hashtable hsTable);
        
        /// <summary>
        /// 修改
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <param name="setValue"></param>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        int Update<T>(T model, string setValue, string strWhere);
        #endregion

        #region 插入--郭文昊--2018年8月9日23:30:31
        /// <summary>
        /// 插入方法
        /// </summary>
        /// <param name="hsTable"></param>
        void Insert<T>(T model, ref Hashtable hsTable);

        /// <summary>
        /// 插入
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        int Insert<T>(T model);
        #endregion

        #region 执行一条sql提交事务--郭文昊--2018年8月14日21:48:48
        /// <summary>
        /// 执行一条sql提交事务
        /// </summary>
        /// <param name="strSql"></param>
        /// <returns></returns>
        bool Execute(string strSql);
        /// <summary>
        /// 直接执行一条sql
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        int ExcSql(string sql);
        #endregion

        #region 提交事务--支持乐观锁--郭文昊--2018年8月9日23:31:50
        /// <summary>
        /// 提交事务
        /// </summary>
        /// <param name="hsTable"></param>
        /// <returns></returns>
        bool CommitDapperTranLock(Hashtable hsTable);
        #endregion

        #region 查询用户数量--郭文昊--2018年10月28日18:58:09
        /// <summary>
        /// 查询用户数量
        /// </summary>
        /// <typeparam name="R"></typeparam>
        /// <param name="sql"></param>
        /// <returns></returns>
        Task<long> QueryCount<T>(string sql);
        #endregion
        /// <summary>
        /// 执行存储过程
        /// </summary>
        /// <param name="procName">存储过程名称</param>
        /// <param name="param">参数</param>
        /// <returns></returns>
        bool ExecProc(string procName, DynamicParameters param);
        /// <summary>
        /// 写入消费表
        /// </summary>
        /// <param name="req"></param>
        /// <param name="hstable"></param>
        void InsertConsumption(Consumption req, ref Hashtable hstable);

        /// <summary>
        /// 判断二级密码
        /// </summary>
        /// <param name="UserCode"></param>
        /// <param name="SecondPassword"></param>
        /// <returns></returns>
        bool CheckSpassword(string UserCode, string SecondPassword);
        /// <summary>
        /// 查用户信息
        /// </summary>
        /// <param name="UserCode"></param>
        /// <returns></returns>
        UserInforMationDetails GetUserInfo(string UserCode);
    }
}
